import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'
import { AtButton, AtInput } from 'taro-ui'
import { connect } from '@tarojs/redux'
import { dispatcher } from '@opcjs/zoro'

import {getDemo} from '../../service/api'

import './index.less'

@connect(({ counter }) => ({
  counter
}))
class Index extends Component {
  config = {
    navigationBarTitleText: '首页'
  }


  componentWillMount(){
    getDemo('dada').then(res=>{
      console.log(res)
    })
  }
  handleAdd = () => dispatcher.counter.add()
  handleMinus = () => dispatcher.counter.minus()
  handleAsyncAdd = () => dispatcher.counter.asyncAdd()


  render() {
    const { counter } = this.props

    return (
      <View className='index'>
        <AtButton type='primary' onClick={this.handleAdd}> + </AtButton>
        <AtButton className='todo_btn' type='primary' onClick={this.handleMinus}> - </AtButton>
        <AtButton type='primary' onClick={this.handleAsyncAdd}> 延时+</AtButton>
        <AtInput
          name='value'
          title='计数器'
          type='text'
          placeholder='标准五个字'
          value={counter.num}/>
      </View>
    )
  }
}

export default Index